package com.ruoyi.inspection.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.inspection.domain.GovernCheckTaskItem;
import com.ruoyi.inspection.service.GovernCheckTaskItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 政府下发专项任务检查项表(GovernCheckTaskItem)表控制层
 *
 * @author makejava
 * @since 2024-06-18 10:48:51
 */
@RestController
@Api("任务子项接口")
@RequestMapping("/check/governCheckTaskItem")
public class GovernCheckTaskItemController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private GovernCheckTaskItemService governCheckTaskItemService;

    /**
     * 分页查询
     *
     * @param governCheckTaskItem 筛选条件
     * @return 查询结果
     */
    @ApiOperation("任务子项列表")
    @GetMapping("/list")
    public TableDataInfo queryByPage(GovernCheckTaskItem governCheckTaskItem) {
        startPage();
        List<GovernCheckTaskItem> governCheckTaskItems = this.governCheckTaskItemService.queryByPage(governCheckTaskItem);
        return getDataTable(governCheckTaskItems);
    }

    /**
     * 检查类型
     * @return 查询结果
     */
    @ApiOperation("检查类型")
    @GetMapping("/getTaskItemTypes")
    public AjaxResult getTaskItemTypes() {
        List<String> types = this.governCheckTaskItemService.getCheckTaskTypes();
        return AjaxResult.success(types);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("查看任务子项")
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.governCheckTaskItemService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param governCheckTaskItem 实体
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult add(@RequestBody GovernCheckTaskItem governCheckTaskItem) {
        governCheckTaskItem.setGovernCreateBy(getUsername());
        return AjaxResult.success(this.governCheckTaskItemService.insert(governCheckTaskItem));
    }

    /**
     * 编辑数据
     *
     * @param governCheckTaskItem 实体
     * @return 编辑结果
     */
    @PutMapping
    public AjaxResult edit(@RequestBody GovernCheckTaskItem governCheckTaskItem) {
        governCheckTaskItem.setGovernUpdateBy(getUsername());
        return AjaxResult.success(this.governCheckTaskItemService.update(governCheckTaskItem));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id) {
        return AjaxResult.success(this.governCheckTaskItemService.deleteById(id));
    }

    @Log(title = "检查项", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('check:governCheckTaskItem:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GovernCheckTaskItem governCheckTaskItem){
        List<GovernCheckTaskItem> taskItems = this.governCheckTaskItemService.queryByPage(governCheckTaskItem);
        ExcelUtil<GovernCheckTaskItem> util = new ExcelUtil<GovernCheckTaskItem>(GovernCheckTaskItem.class);
        util.exportExcel(response, taskItems, "检查项");
    }

//    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:import')")
//    @PostMapping("/importData")
//    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception{
//        ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
//        List<SysUser> userList = util.importExcel(file.getInputStream());
//        String operName = getUsername();
//        String message = userService.importUser(userList, updateSupport, operName);
//        return success(message);
//    }
//
//    @PostMapping("/importTemplate")
//    public void importTemplate(HttpServletResponse response){
//        ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
//        util.importTemplateExcel(response, "用户数据");
//    }

}

